<!--
* 严肃声明：
* 开源版本请务必保留此注释头信息，若删除gemframe官方保留所有法律责任追究！
* 本软件受国家版权局知识产权以及国家计算机软件著作权保护（登记号：2018SR503328）
* 不得恶意分享产品源代码、二次转售等，违者必究。
* Copyright (c) 2020 gemframework all rights reserved.
* http://www.gemframework.com
* 版权所有，侵权必究！
*/
-->
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <div th:replace="common/links::common_links"></div>
    <div th:replace="common/links::custom_links"></div>
    <div th:replace="common/links::font_links"></div>
    <div th:replace="common/links::ztree_links"></div>
    <div th:replace="common/links::multiselect_links"></div>
    <div th:replace="common/links::tabs_links"></div>
    <div th:replace="common/links::checkbox_links"></div>
    <div th:replace="common/links::validate_links"></div>
</head>
<body style="border-radius: 8px;width: 400px;overflow: hidden">
<div>
    <form id="form" onsubmit="return false">
        <div class="top">
            <div>
                <div class="top_out">
                    <table class="table">
                        <tbody>
                        <tr>
                            <td>所属模块
                                <span class="span">*</span></td>
                            <td>
                                <select id="moduleId" name="moduleId" class="block">
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>字段名称
                                <span class="span">*</span></td>
                            <td>
                                <input type="text" id="attrName" name="attrName" class="block" required
                                       maxlength="50">
                            </td>
                        </tr>
                        <tr>
                            <td>字段排序</td>
                            <td>
                                <input type="text" id="attrSort" name="attrSort" class="block" maxlength="2" value="99">
                            </td>
                        </tr>
                        <tr>
                            <td>字段描述</td>
                            <td>
                                <input type="text" id="comment" name="comment" class="block" maxlength="80">
                            </td>
                        </tr>
                        <tr>
                            <td>字段类型
                                <span class="span">*</span></td>
                            <td>
                                <select id="attrType" name="attrType" class="block" onchange="changeAttrType(this.value)">

                                    <option value="text">字符型</option>
                                    <option value="password">密码型</option>
                                    <option value="textarea">文本型</option>
                                    <option value="number">数值型</option>
                                    <option value="hidden">隐藏型</option>
                                    <option value="select">下拉型</option>
                                    <option value="checkbox">多选型</option>
                                    <option value="radio">单选型</option>
                                    <option value="email">邮箱型</option>
                                </select>
                            </td>
                        </tr>
                        <tr id="options_tr" style="display: none">
                            <td>下拉框值</td>
                            <td>
                                <textarea id="options" name="options" placeholder="输入格式：k1=v1;k2=v2...."></textarea>
                            </td>
                        </tr>
                        <tr>
                            <td>最小长度
                                <span class="span">*</span></td>
                            <td>
                                <input type="text" id="minLength" name="minLength" class="block" required
                                       maxlength="10">
                            </td>
                        </tr>
                        <tr>
                            <td>最大长度
                                <span class="span">*</span></td>
                            <td>
                                <input type="text" id="maxLength" name="maxLength" class="block" required
                                       maxlength="10">
                            </td>
                        </tr>
                        <tr>
                            <td>表格编辑
                                <span class="span">*</span></td>
                            <td>
                                <input type="text" id="editType" name="editType" class="block" value="text" required maxlength="10">
                            </td>
                        </tr>
                        <tr>
                            <td>是否为空
                                <span class="span">*</span></td>
                            <td>
                                <select id="isNull" name="isNull" class="block">
                                    <option value="1">支持</option>
                                    <option value="0">不支持</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>是否可见
                                <span class="span">*</span></td>
                            <td>
                                <select id="isVisit" name="isVisit" class="block">
                                    <option value="1">支持</option>
                                    <option value="0">不支持</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>是否排序
                                <span class="span">*</span></td>
                            <td>
                                <select id="isSort" name="isSort" class="block">
                                    <option value="1">支持</option>
                                    <option value="0">不支持</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td>是否查询
                                <span class="span">*</span></td>
                            <td>
                                <select id="isSearch" name="isSearch" class="block">
                                    <option value="1">支持</option>
                                    <option value="0">不支持</option>
                                </select>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!--底部按钮-->
        <div class="notice_bot">
            <div class="l_left">
                <input id="btn_save_close" type="checkbox" checked="checked"/>保存并关闭窗口
            </div>
            <div class="r_right but_p">
                <button class="but_save" type="button" onclick="addData()">保存</button>
                <button class="but_close" onclick="Colse()">关闭</button>
            </div>
        </div>
    </form>
</div>
<div th:replace="common/links::layui_links"></div>
<div th:replace="common/links::common_script"></div>
<div th:replace="common/links::table_script"></div>
<div th:replace="common/links::ztree_script"></div>
<div th:replace="common/links::multiselect_script"></div>
<script type="text/javascript" th:src="@{/static/js/custom/ztree.js}"></script>
<script type="text/javascript" th:src="@{/static/js/custom/depttree.js}"></script>
<script type="text/javascript" th:src="@{/static/js/custom/address.js}"></script>
<div th:replace="common/links::validate_script"></div>
<script>
    $(function(){
        findModules();
    });
    var moduleId = [[${moduleId}]];
    function findModules() {
        $.ajax({
            type: "GET",
            url: "../module/list?moduleId="+moduleId,
            async: true, // 异步请求
            cache: false, // 设置为 false 将不缓存此页面
            dataType: "json", // 返回对象
            success: function (res) {
                if (res.code == "0") {
                    var modules = res.data;
                    if(modules.length > 0){
                        for(i = 0; i < modules.length ; i++){
                            var module = modules[i];
                            $("#moduleId").append("<option value="+module.id+">"+module.nameCn+"</option>");
                        }
                    }
                } else {
                    layer.alert("[" + res.code + "]" + res.msg, {
                        skin: 'layui-layer-lan'
                        ,closeBtn: 0
                    });
                }
            },
            error: function (e) {
                // 请求失败函数
                console.log("error:" + JSON.stringify(e));
                layer.msg("操作失败，请检查是否有相关操作权限！");
            }
        })
    }

    function changeAttrType(val) {
        if(val == "select"){
            $("#options_tr").css('display','');
        }else{
            $("#options_tr").css('display','none');
        }
    }

    function addData() {
        if ($("#form").valid()) {
            $.ajax({
                type: "post",
                url: "add",
                data: JSON.stringify($('#form').serializeObject()),
                async: true, // 异步请求
                cache: false, // 设置为 false 将不缓存此页面
                dataType: "json", // 返回对象
                contentType: "application/json;charset=UTF-8",
                success: function (res) {
                    if (res.code == "0") {
                        if ($("#btn_save_close").is(':checked')) {
                            alert("保存成功", Colse);
                        }
                    } else {
                        layer.alert("[" + res.code + "]" + res.msg, {
                            skin: 'layui-layer-lan'
                            ,closeBtn: 0
                        });
                    }
                },
                error: function (e) {
                    // 请求失败函数
                    console.log("error:" + JSON.stringify(e));
                    layer.msg("操作失败，请检查是否有相关操作权限！");
                }
            })
        }
    }

    function Colse() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }
</script>
</body>
</html>
